--[[
	根据节点config_xxnode 的配置，打开各种级别的日志
	在debug 的runtime下，还可以打印到屏幕上
]]
local skynet = require "skynet"
local base = require "base"
local log = require "log"
local  FileLog = {}

setmetatable(FileLog, {__index = log})

local print = FileLog.print

function FileLog.print(...)
	if(base.isdebug()) then
		print(...)
	end
end

function FileLog.sys_error(...)
	if not skynet.getenv("error") == "false" then
		return
	end
	if(base.isdebug()) then
		print("filelog@error:",base.get_debuginfo(3), ...)
	end
	skynet.send(".nodelog","lua", "error", "servicename:"..SERVICE_NAME.." service_id:"..skynet.self(), ...)
end

function FileLog.sys_info(...)
	if not skynet.getenv("info") == "false" then
		return
	end
	if(base.isdebug()) then
		print("filelog@info:", base.get_debuginfo(3), ...)
	end
	skynet.send(".nodelog", "lua", "info", "servicename:"..SERVICE_NAME.." service_id:"..skynet.self(), ...)
end

function FileLog.sys_warning(...)

	if skynet.getenv("warning") == "false" then
		return
	end
    if(base.isdebug()) then
		print("filelog@warn:",base.get_debuginfo(3), ...)
	end

	skynet.send(".nodelog", "lua", "warning", "servicename:"..SERVICE_NAME.." service_id:"..skynet.self(), ...)
end

function FileLog.sys_protomsg(msgname,...)
	if skynet.getenv("protomsg") == "false" then
		return
	end	
	if msgname == nil or type(msgname) ~= "string" then
		return
	end
	if(base.isdebug()) then
		print("filelog@proto:", msgname, ...)
	end
	skynet.send(".nodelog", "lua", "protomsg", msgname, "servicename:"..SERVICE_NAME.." service_id:"..skynet.self(), ...)
end

function FileLog.sys_reload()
	skynet.send(".nodelog", "lua", "reload")
end

function FileLog.sys_exit()
	skynet.send(".nodelog", "lua", "exit")
end

function FileLog.sys_obj(objname, objid, ...)
	if not skynet.getenv("obj") then
		return
	end	
 	if objname == nil then
 		objname = "object"
 	end
 	if objid == nil  then
 		objid = "objectid"
 	end
	skynet.send(".nodelog", "lua", "obj", objname, objid, "servicename:"..SERVICE_NAME.." service_id:"..skynet.self(), ...)
end

return FileLog
